package com.briup.day19;

public class ThreadTest4 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            Thread thread = Thread.currentThread();
            System.out.printf("当前线程%s的状态:%s%n", thread.getName(), thread.getState());
        });
        Thread t2 = new Thread(() -> {
            try {
                t.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            Thread thread = Thread.currentThread();
            System.out.printf("当前线程%s的状态:%s%n", thread.getName(), thread.getState());
        });
        System.out.printf("当前线程%s的状态:%s%n", t.getName(), t.getState());
        t.start();
        t2.start();
        // 获取t线程状态
        System.out.printf("当前线程%s的状态:%s%n", t.getName(), t.getState());
        Thread thread = Thread.currentThread();
        System.out.printf("当前线程%s的状态:%s%n", thread.getName(), thread.getState());
        System.out.printf("当前线程%s的状态:%s%n", t.getName(), t.getState());
        System.out.printf("当前线程%s的状态:%s%n", t.getName(), t.getState());
        System.out.printf("当前线程%s的状态:%s%n", t2.getName(), t2.getState());

        // 让t线程先执行完任务后在执行后续操作
        t.join();
        System.out.printf("当前线程%s的状态:%s%n", t.getName(), t.getState());
    }
}
